package com.tjec.framework.quartz;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.tjec.project.businessWorkbench.dto.BmsTaskTimerDto;
import com.tjec.project.businessWorkbench.service.IBmsBusinessTaskService;
import com.tjec.project.msg.service.MsgService;

/**
 * 
 * @author pangyongfeng
 *
 */

@Component
@PropertySource("classpath:/quartz.properties")
public class TaskSchedule {
	@Resource
	private IBmsBusinessTaskService businessTaskService;
	 
	@Resource
	private MsgService msgService;
	
	/**
     * 每天的8点半执行
     */
//	 生产服务器EC1定时任务:
//	 @Scheduled(cron = "0 40 8 * * ?")
//	 生产服务器EC2定时任务:
//	 @Scheduled(cron = "0 30 8 * * ?")
    @Scheduled(cron="${businessWorkbench.tasking.timer}")
    public void cronJob1(){
    	//sengMsgToExecute();
    }
    
    /**
     * 每天的16点半执行
     */
//	 生产服务器EC1定时任务:
//	 @Scheduled(cron = "0 40 16 * * ?")
//	 生产服务器EC2定时任务:
//	 @Scheduled(cron = "0 30 16 * * ?")
    @Scheduled(cron="${businessWorkbench.tasked.timer}")
    public void cronJob2(){
    	sengMsgToExecute();  
    }
    
    public void sengMsgToExecute() {
    	List<BmsTaskTimerDto> resList = businessTaskService.selectAllMsgTask();
    	if(resList!=null && resList.size()>0) {
    		resList.forEach(item->{
    			if(item.getCounts()<2) {
    				msgService.SendMsg2(item.getExecutePhone(), item.getExecuteName()+"：“您的任务【"+item.getTaskName()+"】计划本日完成，请尽快完成。”");
    				item.setCounts(item.getCounts()+1);
    				businessTaskService.updateTaskCounts(item);
    			}
    			
    		});
    	}
    }
}
